﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using Charades.Web.Helpers;
using Newtonsoft.Json;

namespace Charades.Web.Server.User
{
	public class User
	{
		public User(string connectionId, string name, string color = "", string id = "")
		{
			Id = string.IsNullOrEmpty(id) ? RandomNameHelper.GetName(5) : HttpUtility.HtmlEncode(id);
			ConnectionId = connectionId;
			Name = name;
			Color = string.IsNullOrEmpty(color) ? ColorHelper.GenerateColor() : color;
			BannedStack = new List<string>();
		}

		[JsonIgnore]
		public string ConnectionId { get; protected set; }

		[JsonProperty("id")]
		public string Id { get; protected set; }

		[JsonProperty("name")]
		public string Name { get; protected set; }

		[JsonProperty("color")]
		public string Color { get; set; }

		[JsonProperty("points")]
		public int Points { get; set; }

		[JsonIgnore]
		public string RoomId { get; set; }

		public List<string> BannedStack { get; protected set; }

		public override string ToString()
		{
			var userSerialized = String.Format(
				"Id:{0};ConnectionId:{1};Name:{2};Color:{3};Points:{4};RoomId:{5}",
				Id, ConnectionId, Name, Color, Points, RoomId);

			return userSerialized;
		}
	}
}